//
//  JDefine.h
//  jhf
//
//  Created by 计海峰 on 2017/11/23 14:05:37.
//  Copyright © 2017年 计海峰. All rights reserved.
//

#ifndef JDefine_h
#define JDefine_h

#define JBundelName @"JBaseWorking.bundle"

#define jBaseSDK [CrosheSDK shareInstance]


//-------------------提示信息  开始-------------------------

#define WTHUD [JProgressHUD showMessage:nil];

#define WTHUD_VIEW(A) [JProgressHUD showMessage:nil toView:A];

#define WHUD(A) [JProgressHUD showMessage:A];

#define WHUD_VIEW(A,B) [JProgressHUD showMessage:A toView:B];

#define HHUD [JProgressHUD hideHUD];

#define HHUD_VIEW(A) [JProgressHUD hideHUDForView:A];

#define NHUD(A) [JProgressHUD showInfo:A];

#define NHUD_VIEW(A,B) [JProgressHUD showInfo:A toView:B];

#define EHUD(A) [JProgressHUD showError:A];

#define EHUD_VIEW(A,B) [JProgressHUD showError:A toView:B];

#define SHUD(A) [JProgressHUD showSuccess:A];

#define SHUD_VIEW(A,B) [JProgressHUD showSuccess:A toView:B];


#define PHUD(A,B)  A >=1 ? [JProgressHUD hideHUD] : [JProgressHUD showProgress:A andInfo:B];
//-------------------提示信息  结束-------------------------
  
//-------------------BlockValue-------------------------
typedef void(^BlockValue)(NSInteger idx, NSObject * item);

typedef void(^BlockResult)(NSInteger idx, id item);

typedef void(^BlockBool)(BOOL result);

typedef void(^BlockId)(id obj);

typedef void(^BlockInteger)(NSInteger num);

typedef void(^BlockDouble)(double db);

//-------------------出去SEL警告-------------------------
//[self performSelector:action])
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0);

//-------------------出去类型不符警告-------------------------
#define SuppressPointerLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wincompatible-pointer-types\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0);

//简写代码  宏定义
#define jWeakself __weak typeof(self) weakSelf = self;

#define jStrongSelf(type)  __strong typeof(type) strongSelf = type;

#define jWeakName(weakSelf)  __weak __typeof(&*self)weakSelf = self;


//定义NSInteger 转 NSString
#define IntToSting(A) [NSString stringWithFormat:@"%ld",(long)A]

#define FloatToSting(A) [NSString stringWithFormat:@"%f",A]


#define JViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

//-------------------获取沙盒-------------------------
//获取temp
#define kPathTemp NSTemporaryDirectory()

//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]


//-------------------获取设备大小 开始-------------------------
//NavBar高度
#define NavigationBar_HEIGHT 44


//应用尺寸(不包括状态栏,通话时状态栏高度不是20，所以需要知道具体尺寸)
#define kContent_Height   ([UIScreen mainScreen].applicationFrame.size.height)
#define kContent_Width    ([UIScreen mainScreen].applicationFrame.size.width)
#define kContent_Frame    (CGRectMake(0, 0 ,kContent_Width,kContent_Height))
#define kContent_CenterX  kContent_Width/2
#define kContent_CenterY  kContent_Height/2


//设备屏幕尺寸
#define kScreen_Height   ([UIScreen mainScreen].bounds.size.height)
#define kScreen_Width    ([UIScreen mainScreen].bounds.size.width)
#define kScreen_Frame    (CGRectMake(0, 0 ,kScreen_Width,kScreen_Height))
#define kScreen_CenterX  kScreen_Width/2
#define kScreen_CenterY  kScreen_Height/2

//弹出信息
#define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil] show]

//App
#define kApp ((AppDelegate *)[UIApplication sharedApplication].delegate)
#define kNav ((AppDelegate *)[UIApplication sharedApplication].delegate.navigationController)


//-------------------打印日志 开始-------------------------
#define DLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

//DEBUG  模式下打印日志,当前行 并弹出一个警告
#ifdef DEBUG
#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define ULog(...)
#endif


#define ITTDEBUG
#define ITTLOGLEVEL_INFO     10
#define ITTLOGLEVEL_WARNING  3
#define ITTLOGLEVEL_ERROR    1

#ifndef ITTMAXLOGLEVEL

#ifdef DEBUG
#define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
#else
#define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
#endif

#endif

//---------------------打印日志 结束--------------------------


//----------------------系统 开始----------------------------
//获取系统版本
#define IOS_SYSTEM_FLOAT [[[UIDevice currentDevice] systemVersion] floatValue]
#define IOS_SYSTEM_STRING [[UIDevice currentDevice] systemVersion]

//判断 iOS 或更高的系统版本
#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))
#define IOS_VERSION_11_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=11.0)? (YES):(NO))

//获取 版本号
#define JCurrentFloatVersion [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] floatValue]
#define JCurrentVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//获取 build版本
#define JCurrentBuild [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

//获取 当前应用名称
#define JDisplayName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

//获取工程名
#define JProductName [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey]

//获取小写工程名
#define JProductLowerName [[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] lowercaseString]

//获取当前语言
#define JCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

//是否是iPhoneX
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

//判断设备
#define iPhone6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

//判断是否为iPhone
#define IS_IPHONE ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])

//判断是否为iPad
#define IS_IPAD ([[[UIDevice currentDevice] model] isEqualToString:@"iPad"])

//判断是否为ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//----------------------系统 结束----------------------------



//----------------------内存 开始----------------------------

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

//释放一个对象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }

#define SAFE_RELEASE(x) [x release];x=nil


//----------------------内存 结束----------------------------


//----------------------本地资源 开始----------------------------
//读取本地plist
#define JLOCAL_PLIST_PATH(file) [[NSBundle mainBundle] pathForResource:file ofType:@"plist"]

#define JLOAD_ARRAY_PLIST(file) [[NSMutableArray alloc] initWithContentsOfFile:JLOCAL_PLIST_PATH(file)]
#define JLOAD_DIC_PLIST(file) [[NSMutableDictionary alloc] initWithContentsOfFile:JLOCAL_PLIST_PATH(file)]

//读取本地文件
#define JLOCAL_FILE_PATH(file) [[NSBundle mainBundle] pathForResource:file ofType:nil]

#define JLOCAL_FILE_DATA(file) [NSData dataWithContentsOfFile:JLOCAL_FILE_PATH(file)]

#define JLOCAL_FILE_JSON_ID(file) [NSJSONSerialization JSONObjectWithData:JLOCAL_FILE_DATA(file) options:NSJSONReadingMutableContainers error:nil]

//读取Bundle文件
#define JLOAD_Bundle(ClassName, BundleName) [NSBundle bundleWithPath:[[NSBundle bundleForClass:NSClassFromString(ClassName)] pathForResource:BundleName ofType:@"bundle"]]

#define JLOAD_Bundle_IMAGE(ClassName, BundleName, ImageName) [[UIImage imageWithContentsOfFile:[JLOAD_Bundle(ClassName, BundleName) pathForResource:ImageName ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]


//读取本地图片
#define JLOAD_IMAGE_TYPE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]

#define JLOAD_IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

#define JIMAGE_NAMED(name) [UIImage imageNamed:name]

//读取本地Storyboard
#define JLOADSTORYBOARD(storyboardName,controllerIdentifier) [[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateViewControllerWithIdentifier:controllerIdentifier]
//----------------------本地资源 结束----------------------------


//----------------------颜色类 开始---------------------------
// 获取RGB颜色
#pragma mark - color functions

#define JRGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]

#define JRGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

#define JRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

#define JCOLORWITHHEX(A) [UIColor colorWithHexString:A]

#define JCLEARCOLOR [UIColor clearColor]

//----------------------颜色类 结束---------------------------

//----------------------电话 url 开始---------------------------
//拨打电话
#define canTel                 ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]])
#define tel(phoneNumber)       ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]])
#define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]])

//打开URL
#define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]])
#define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])

//----------------------电话 url 结束---------------------------


//----------------------其他----------------------------

//NSUserDefaults 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//NotificationCenter 实例化
#define NotificationCenter [NSNotificationCenter defaultCenter]

//方正黑体简体字体定义
#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//设置View的tag属性
#define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]

//程序的本地化,引用国际化的文件
#define MyLocal(x, ...) NSLocalizedString(x, nil)

//G－C－D
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)


//ARC下面 单例化一个类

// .h文件
#define JSingletonH(name) + (instancetype)shared##name;

// .m文件
#define JSingletonM(name) \
static id _instance; \
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
\
+ (instancetype)shared##name \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return _instance; \
}


#endif /* JDefine_h */
